//本地配置
var rootPath = getRootPath(); //静态资源
var apiPath = "http://127.0.0.1:7070";
var socketPath;

//外网配置
//var apiPath = "https://www.irobotop.com/chats";
//socketPath = "ws://8.133.188.238:7070";

console.log("rootPath==>>"+ rootPath);
console.log("apiPath==>>"+ apiPath);

/**
 * 动态加载CSS和JS文件
 */
var dynamicLoading = {
	meta: function() {
		document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
	},
	html: function(html) {
		document.write(html);
	},
	css: function(path) {
		if(!path || path.length === 0) {
			throw new Error('argument "path" is required!');
		}
		path += "?f=" + Math.random();
		document.write('<link rel="stylesheet" type="text/css" href="' + path + '">');
	},
	js: function(path, charset) {
		if(!path || path.length === 0) {
			throw new Error('argument "path" is required!');
		}
		document.write('<script charset="' + (charset ? charset : "utf-8") + '" src="' + path + '"></script>');
	}
};

/**
 * 取得项目路径
 * @author wul
 */
function getRootPath() {
	//取得当前URL
	var path = window.document.location.href;
	//取得主机地址后的目录
	var pathName = window.document.location.pathname;
	var post = path.indexOf(pathName);
	//取得主机地址
	var hostPath = path.substring(0, post);
	//取得项目名
	var name = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
	return hostPath + name + "/";
}

//动态生成meta
dynamicLoading.meta();

//动态加载项目 CSS文件
dynamicLoading.css("layui/css/layui.css");

//自定义js、获取页面跳转url后面的参数
dynamicLoading.js("static/js/jquery-1.8.2.min.js", "utf-8");
dynamicLoading.js("static/js/getparam.js", "utf-8");
dynamicLoading.js("layer/layer.js", "utf-8");
dynamicLoading.js("layui/layui.js", "utf-8");

/*3、loadHeader.js 
$(function(){
    $(".container").append('<div id="header"></div>');
    $("#header").load(getRootPath() + "header.html");
});*/

//公用JS
//获取地址栏后的参数方法

function _success(msg) {
    layer.msg(msg,{icon: 1, time: 1200});
}
function _failMsg(msg) {
    layer.msg(msg,{icon: 2, time: 1400});
}

function  _get(name) {
	var  reg = new  RegExp("(^|&)" + name + "=([^&]*)(&|$)");     
	var  r = window.location.search.substr(1).match(reg);     
	if(r != null){
		r = unescape(r[2]);
		return decodeURI(r);
	}
	return  null;
};
function  _isNull(name) {
	if(name == null || name == undefined || name == "" || name == "null"){
		return true;
	}
	return false;
};
function  _isNotNull(name) {
	if(name != null && name != "" && name != "null"){
		return true;
	}
	return false;
};

function _getDate(){
	var dateStr = _getYear() + "-" + _getMonth() + "-" + _getDay();
	return dateStr;
}

function _getYear(){
	return new Date().getFullYear();
}
function _getMonth(){
	var month = (new Date().getMonth() + 1) + "";
	month = month.length < 2? 0+month :  month;
	return  month;
}
function _getDay(){
	var day = new Date().getDate() + "";
	day = day.length < 2? 0+day :  day;
	return day;
}